CC=g++
CC_FLAGS=-c -Wall #-DSHOW_FREE

LINK=g++
LINK_FLAGS=

RM=rm -f

BIN_OUT=parser
BIN_XSL=xslout
BIN_TEST=tests

INC_DIR=
LIB_DIR=
LIBS=-lboost_regex

OBJECTS=validator.o xml/Attribute.o xml/Content.o xml/Element.o xml/Node.o dtd/Printer.o dtd/DTDElement.o dtd/Mixte.o dtd/Name.o dtd/AttList.o dtd/Attribut.o dtd/Children.o dtd/Choice.o dtd/ContentParticules.o dtd/DTD.o dtd/Sequence.o dtd/SimpleName.o xsl/StyleSheet.o xsl/Template.o
LEXS=xml/lex.xml.o dtd/lex.dtd.o
BISONS=xml/xml.tab.o dtd/dtd.tab.o

$(BIN_OUT): Makefile $(OBJECTS) $(BISONS) $(LEXS) main.o
	$(LINK) -o $(BIN_OUT) $(OBJECTS) main.o $(BISONS) $(LEXS) $(LIB_DIR) $(LIBS)

$(BIN_XSL): Makefile $(OBJECTS) $(BISONS) $(LEXS) xsl/main.o
	$(LINK) -o $(BIN_XSL) $(OBJECTS) xsl/main.o $(BISONS) $(LEXS) $(LIB_DIR) $(LIBS)

$(BIN_TEST): Makefile $(OBJECTS) $(BISONS) $(LEXS) test/test.cpp
	$(LINK) -o $(BIN_TEST) $(OBJECTS) test/test.cpp $(BISONS) $(LEXS) $(LIB_DIR) $(LIBS)

all: $(BIN_OUT) $(BIN_TEST) $(BIN_TEST)

clean:
	$(RM)	$(BIN_OUT) $(BIN_XSL) $(BIN_TEST)
	$(RM)	$(OBJECTS) $(BISONS) $(LEXS)
	$(RM)	.*swp main.o
	$(RM)	dtd/*.tab.h dtd/*.tab.c dtd/lex.*.c xml/*.tab.h xml/*.tab.c xml/lex.*.c dtd/*.output xml/*.output

$(LEXS) $(BISONS):%.o: %.c
	$(CC) $(CC_FLAGS) $(INC_DIR) $< -o $@

%.o: %.cpp
	$(CC) $(CC_FLAGS) $(INC_DIR) $< -o $@

lex.%.c: %.l
	flex -o$@ $<

dtd/dtd.tab.c: dtd/dtd.y
	bison --debug --verbose -p dtd --defines=dtd/dtd.tab.h $< -o $@

xml/xml.tab.c: xml/xml.y
	bison --debug --verbose -p xml --defines=xml/xml.tab.h $< -o $@
